//
//  TTWecomeController.swift
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/22.
//  Copyright © 2016年 陶路路. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class TTWecomeController: UIViewController {

    lazy var imageView: UIImageView = {
       let img = UIImageView()
        img.image = UIImage(named: "ad_background")
        return img
    }()
    
    lazy var headImage:UIImageView = {
       
        let head = UIImageView()
                
        head.sd_setImageWithURL(NSURL(string: (string:TTOAutoModel.sharedOautoModel.userModel?.avatar_large) ?? ""), placeholderImage: UIImage(named: "avatar_default_big"))
        head.layer.cornerRadius = 45
        head.layer.masksToBounds = true
        head.layer.borderColor = UIColor.orangeColor().CGColor
        head.layer.borderWidth = 2
        return head
    }()
    
    lazy var lable : UILabel = {
       let text = UILabel()
        text.text = "欢迎回来"
        text.font = UIFont.systemFontOfSize(20)
        text.textAlignment = .Center
        text.alpha = 0
        return text
    }()
    
    override func loadView() {
        
        view = imageView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        imageView.addSubview(headImage)
        imageView.addSubview(lable)
        setUpUI()
    }

    func setUpUI(){
    
        headImage.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(self.view)
            make.width.height.equalTo(90)
            make.top.equalTo(self.view).offset(400)
        }
       
        lable.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(headImage)
            make.top.equalTo(headImage.snp_bottom).offset(16)
        }
    }
    
    override func viewDidAppear(animated: Bool) {
        
        super.viewDidAppear(animated)
        
        self.headImage.snp_updateConstraints { (make) -> Void in
            
            make.top.equalTo(self.view.snp_top).offset(100)
        }
        
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                
                UIView.animateWithDuration(0.5, animations: { () -> Void in
                    
                    self.lable.alpha = 1
                    
                    }, completion: { (_) -> Void in
                        
                        NSNotificationCenter.defaultCenter().postNotificationName("TTWecomeController", object: self)
                })
             
                
                
        }
    }
 
    deinit{
        
    }
}
